package jsyf.oa.web.system;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.system.Enum2Facade;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.alibaba.dubbo.common.utils.StringUtils;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(value = "枚举选项接口", description = "枚举选项接口")
@Controller
@RequestMapping("/enum2")
public class Enum2Controller {
    @Resource
    private Enum2Facade enum2Facade;

    @RequestMapping(value = "/selectByModuleType.json", method = RequestMethod.POST)
    public void selectByModuleType(HttpServletResponse response, @RequestBody String jsonData) {
        List<JSONObject> objectList = enum2Facade.selectByModuleType(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(objectList));
    }

    @RequestMapping(value = "/delById.json", method = RequestMethod.POST)
    public void delById(HttpServletResponse response, @RequestBody String jsonData) {
        Boolean flag = enum2Facade.delById(jsonData);
        if(flag){
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond("删除成功"));
        }else{
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("删除失败"));
        }


    }

    @RequestMapping(value = "/save.json", method = RequestMethod.POST)
    public void save(HttpServletResponse response, @RequestBody String jsonData) {
        String id = enum2Facade.save(jsonData);
        if(!StringUtils.isBlank(id)){
            JSONObject jsonObject =new JSONObject();
            jsonObject.put("id",id);
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(jsonObject));
        }else{
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("添加失败"));
        }
    }

    @RequestMapping(value = "/moduleTypeList.json", method = RequestMethod.POST)
    public void moduleTypeList(HttpServletResponse response, @RequestBody String jsonData) {
        List<JSONObject> objectList = enum2Facade.moduleTypeList();
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(objectList));
    }

    @RequestMapping(value = "/getById.json", method = RequestMethod.POST)
    public void getById(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonObject = enum2Facade.getById(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(jsonObject));
    }

}
